// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import (
	"fmt"
	"reflect"
)

type User struct {
	name   string
	userId int
	score  float64
}

type TypeString string

func print(x, y interface{}) {
	t1 := reflect.TypeOf(x)
	k1 := t1.Kind()
	t2 := reflect.TypeOf(y)
	k2 := t2.Kind()
	fmt.Println("Type1:", t1)
	fmt.Println("Kind1:", k1)
	fmt.Println("Type2:", t2)
	fmt.Println("Kind2:", k2)

	fmt.Println("参数x中的值是:")
	if reflect.ValueOf(x).Kind() == reflect.Struct {
		value := reflect.ValueOf(x)
		numberOfFields := value.NumField()
		for i := 0; i < numberOfFields; i++ {
			fmt.Printf("Type:%T || Value:%#v\n",
				value.Field(i), value.Field(i))
			fmt.Println("类型：", value.Field(i).Kind())
		}
	}
	value := reflect.ValueOf(y)
	fmt.Printf("y的值是 %#v", value)
}

func main() {
	str := TypeString("666")
	person := User{
		name:   "ShirDon",
		userId: 6,
		score:  99.5,
	}
	print(person, str)
}

//$ go run reflect1.go
//Type1: main.User
//Kind1: struct
//Type2: main.TypeString
//Kind2: string
//参数x中的值是:
//Type:reflect.Value || Value:"ShirDon"
//类型： string
//Type:reflect.Value || Value:6
//类型： int
//Type:reflect.Value || Value:99.5
//类型： float64
//y的值是 "666"
